import crypto from 'crypto';

/**
 * 生成密钥对 (EC P-256)
 * @param output 输出文件路径
 */
export default function kp(output: string) {
  const keyPair = crypto.generateKeyPairSync('ec', {
    namedCurve: 'P-256',
  });

  const publicKey = keyPair.publicKey.export({
    type: 'spki',
    format: 'pem'
  });

  const privateKey = keyPair.privateKey.export({
    type: 'pkcs8', 
    format: 'pem'
  });

  const fs = require('fs');
  const path = require('path');

  fs.writeFileSync(path.join(output, 'public.pem'), publicKey);
  fs.writeFileSync(path.join(output, 'private.pem'), privateKey);
}
